/*  BEGIN_FILE_HDR
******************************************Copyright(C)*****************************************
*
*                                       YKXH  Technology
*
***********************************File Info***************************************************
*   File Name       @: Ccp_Cbk.c
************************************************************************************************
*   Project/Product @: Ccp_Cbk
*   Title           @: Ccp_Cbk.h 
*   Author          @: zhongliang.Yang 
************************************************************************************************
*   Description     @: 
*                     
************************************************************************************************
*   Limitations     @: None
*
************************************************************************************************
*
************************************************************************************************
*   Revision History:
* 
*   Version     Date          Initials           CR#         Descriptions
*   --------    -----------   ----------------   --------    -----------------------
*   1.0         2018/05/29    zhongliang.yang    N/A         Original 
*   1.1         xxxx/xx/xx    xxxxx              N/A         xxxxxxxx 
*     
************************************************************************************************
* END_FILE_HDR*/

#include "Ccp.h"

/*******************************************************************************
*   Macro definition 
*******************************************************************************/
#define CCP_FLASH_WRITE_BYTES   128u

/*******************************************************************************
*   Variable definition 
*******************************************************************************/
#define CCP_START_SEC_VAR_UNSPECIFIED
#include "../src/BSW/CommS/NM/YKBase/MemMap.h"

/*Program Related*/
#ifdef CCP_FLASH


#define CCP_STOP_SEC_VAR_UNSPECIFIED
#include "../src/BSW/CommS/NM/YKBase/MemMap.h"
/*******************************************************************************
*   Function definition 
*******************************************************************************/
#define CCP_START_SEC_PUBLIC_CODE
#include "../src/BSW/CommS/NM/YKBase/MemMap.h"
/* BEGIN_FUNCTION_HDR
********************************************************************************
* Function Name:    CCP_FlashErase 
*                
* Description:      This functin is used to erase non-volatile memory. 
*                             
* Inputs:           uint32 Flash_Erase_Ptr: Address to be erased.
*                   uint32 size           : Size to be erased.
*                   
* Outputs:          Std_ReturnType
*                   E_OK:                   Erasing completed. 
*                   E_NOT_OK:               Erasing failure.
*
* Limitations:      None
********************************************************************************
END_FUNCTION_HDR*/

Std_ReturnType Ccp_FlashErase(uint32 Flash_Erase_Ptr, uint32 size) 
{
    /*demo code*/
	
	uint8 count;
	
	for(count=0u;count<size;count++)
	{
		*(((uint8 *)Flash_Erase_Ptr)+count) = 0xff;
	}
	return E_OK;
	
}

/* BEGIN_FUNCTION_HDR
********************************************************************************
* Function Name:    CCP_FlashWrite 
*                
* Description:      This functin is used to write non-volatile memory. 
*                             
* Inputs:           uint8* data:            Source Address to get data.
*                   uint32 Flash_Erase_Ptr: Target Address to be wrote.
*                   uint32 size:            Size to be wrote.
*                   
* Outputs:          Std_ReturnType
*                   E_OK:                   Writing completed. 
*                   E_NOT_OK:               Writing failure.
*
* Limitations:      None
********************************************************************************
END_FUNCTION_HDR*/

Std_ReturnType Ccp_FlashWrite(uint8* data, uint32 Flash_Write_Ptr, uint32 size) 
{

	uint8 count;
	
	for(count=0u;count<size;count++)
	{
		*(((uint8 *)Flash_Write_Ptr)+count) = *(data+count);
	}
	return E_OK;
          
}

/* BEGIN_FUNCTION_HDR
********************************************************************************
* Function Name:    CCP_FlashRead 
*                
* Description:      This functin is used to read data from non-volatile memory. 
*                             
* Inputs:           uint8* data:            Address to store read data.
*                   uint32 Flash_Erase_Ptr: Source Address to get date.
*                   uint32 size:            Size to be read.
*                   
* Outputs:          Std_ReturnType
*                   E_OK:                   Reading completed. 
*                   E_NOT_OK:               Reading failure.
*
* Limitations:      None
********************************************************************************
END_FUNCTION_HDR*/

Std_ReturnType Ccp_FlashRead(uint8* data, uint32 Flash_Read_Ptr, uint32 size) 
{
    uint8 count;
    for(count=0u;count<size;count++)
    {
        data[count] = *(((uint8 *)Flash_Read_Ptr)+count);
    }
    return E_OK;
}
#endif

#ifdef CCP_SEED_KEY
/* BEGIN_FUNCTION_HDR
********************************************************************************
* Function Name:    CCP_GetSeed 
*                
* Description:      This functin is used to get seed to unlock resource. 
*                             
* Inputs:           uint8 Resource_Mask:    Resource type.
*                   
* Outputs:          uint32:                 Seed value
*
* Limitations:      Only used when Seed&Key enable.
********************************************************************************
END_FUNCTION_HDR*/

uint32 Ccp_GetSeed(uint8 Resource_Mask) 
{
    return 123;
}

/* BEGIN_FUNCTION_HDR
********************************************************************************
* Function Name:    CCP_Unlock 
*                
* Description:      This functin is used unlock resource. 
*                             
* Inputs:           uint32 key: Calculated key value.
*                   
* Outputs:          uint8:      If key is right, return CCP_RIGHT_KEY. 
*                               Otherwise, return CCP_WRONG_KEY.
*
* Limitations:      Only used when Seed&Key enable.
********************************************************************************
END_FUNCTION_HDR*/

uint8 Ccp_Unlock(uint32 key)
{
	if(key == 123)
    { 
		return CCP_RIGHT_KEY;
    }
	else
	{
		return CCP_WRONG_KEY;
		
	}
}
#endif

#ifdef  CCP_CAL_PAGE
/* BEGIN_FUNCTION_HDR
********************************************************************************
* Function Name:    Select_Page_Indication 
*                
* Description:      This functin is used to indicate selecting page. 
*                             
* Inputs:           None page_index:       Selected page index.
*                   
* Outputs:          Std_ReturnType
*                   E_OK:                   Selecting completed. 
*                   E_NOT_OK:               Selecting failure.
*
* Limitations:      Only used when Page enable.
********************************************************************************
END_FUNCTION_HDR*/

Std_ReturnType Ccp_Select_Page_Indication(uint8 page_index)
{
    return E_OK;
}
#endif

#ifdef CCP_STORE_CAL_DATA
/* BEGIN_FUNCTION_HDR
********************************************************************************
* Function Name:    Store_Cal_Data 
*                
* Description:      This functin is used to store calbration data to 
*                   non-volatile memory when disconnect. 
*                             
* Inputs:           None
*                   
* Outputs:          None
*
* Limitations:      Only used when Page enable.
********************************************************************************
END_FUNCTION_HDR*/

void Ccp_Store_Cal_Data(void)
{
    /*add your codes here*/
}
#endif

#define CCP_STOP_SEC_PUBLIC_CODE
#include "../src/BSW/CommS/NM/YKBase/MemMap.h"

